package GUI;
/**
 * Show the principle data screen for the selected student
 * for the selected year for the selected class
 */

import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JButton;




public class PrincipleShowDataScreen extends JPanel {
   
	
	
	
    private JLabel lblViewAcademicData = null;
	private JButton btnBack = null;
	private Dimension defaultDim=null;
	private JScrollPane scrollPane=null;
	public String[][]data = null;

	public Login myLoginFrame = null;
	public UserPrinciple user=null;
	public PrincipleMainMenu prmn = null;

	private  JTable dataTable_1=null;
	private String IsExceptional = "Exceptional request approved";
 
    public PrincipleShowDataScreen(PrincipleMainMenu prmn) {
    	
        super(new GridLayout(1,0));
 
       int i,j,k,m,count;
       
       for(i=0;i<prmn.user.StudentsData.size();i++)
       {
    	   if(prmn.user.getSelStudent().endsWith(prmn.user.StudentsData.get(i).Sid))
    	   {
    		   break;
    	   }
       }
        
        
        String[] columnNamesStr = {"Year","Semester","Course", "Grade","Comments", "Evaluation form"};
        data = new String[prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.size()][6];
    	
    	
		//for( m=0, j=0,count=0;i<prmn.user.StudentsData.size();i++)
    	//{
			j=0;
			count=0;
    		for(k=0;k<prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.size();k++)
    		{
    	if((prmn.user.getSelYear()==((prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(k).getYear().toString())))&&
    		(prmn.user.getSelSemester()==(prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(k).getSemester().toString())))
    			
    	{
    		 data[count][j]=prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(k).getYear().toString() ;
    		 data[count][j+1]=prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(k).getSemester().toString();
    		 data[count][j+2]=prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(k).getCname().toString()+" "+ prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(k).getCid().toString();
    		 data[count][j+3]=prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(k).getGrade().toString();
    		 if(!prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(k).getIsExeptional()) IsExceptional=" ";
    		 data[count][j+4]=IsExceptional;// a cell for a link to the evaluation file
    		 data[count][j+5]=null;// a cell for a link to the evaluation file
    		 count++;
    	}	
    	 System.out.println(prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.size());
    	 System.out.println(prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(k).getCid().toString());
    	
    	 System.out.println(prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(k).getCname().toString());
    	 System.out.println(prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(k).getGrade().toString());
    	 System.out.println(prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(k).getYear().toString());
    	 System.out.println(prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(k).getSemester().toString());
    	 System.out.println(prmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(k).getIsExeptional().toString());
    	 
    		}
    	//}
 
         
        final JTable table = new JTable(data, columnNamesStr);
        table.setPreferredScrollableViewportSize(new Dimension(500, 500));
        table.setFillsViewportHeight(true);
        printDebugData(table);
      
        
      
 
        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);
 
        //Add the scroll pane to this panel.
        add(scrollPane);
        
    }
 
    private void printDebugData(JTable table) {
        int numRows = table.getRowCount();
        int numCols = table.getColumnCount();
        javax.swing.table.TableModel model = table.getModel();
 
        System.out.println("Value of data: ");
        for (int i=0; i < numRows; i++) {
            System.out.print("    row " + i + ":");
            for (int j=0; j < numCols; j++) {
                System.out.print("  " + model.getValueAt(i, j));
            }
            System.out.println();
        }
        System.out.println("--------------------------");
    }
 
   
}




